package com.stone.zeus.component.grpc.controller;

import com.stone.zeus.component.grpc.api.microservice.DubboMicroService;
import com.zb.zeus.common.core.exception.BaseException;
import com.zb.zeus.common.core.web.controller.BaseAction;
import com.zb.zeus.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fujianjian
 * @since 2021/7/1 22:07
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/demo")
@Api(value = "DEMO服务接口", tags = "DEMO服务接口")
public class DemoController extends BaseAction {

    private final Environment environment;

    @DubboReference(group = "default", version = "1.0")
    private DubboMicroService dubboMicroService;


    @GetMapping("/greet")
    public AjaxResult greet(String source) {
        try {
            log.info("testsssssssssssssssssssss,{}", source);
            dubboMicroService.hello(source);
            AjaxResult ret = AjaxResult.success(environment.getProperty("spring.application.name"));
            return ret;
        } catch (Exception e) {
            log.error("error", e);
            throw new BaseException("error", e);
        }

    }

}
